﻿package core.manager
{
    import core.enum.*;
    import flash.events.*;

    public class KeyInputManager extends Object
    {
        var ed:Tuyitu;
        var keyed:Boolean = false;
        var spaced:Boolean = false;

        public function KeyInputManager(param1:Tuyitu)
        {
            this.ed = param1;
            param1.stage.addEventListener(KeyboardEvent.KEY_DOWN, this.KeyDown, false, 0, true);
            param1.stage.addEventListener(KeyboardEvent.KEY_UP, this.KeyUp, false, 0, true);
            return;
        }// end function

        public function KeyDown(event:KeyboardEvent) : void
        {
            if (AppState.Modald || AppState.TextInteraction)
            {
                return;
            }
            switch(event.keyCode)
            {
                case 32:
                {
                    if (!this.spaced)
                    {
                        this.spaced = true;
                        this.ed.alt = this.ed.tool.type;
                        this.ed.SetTool(ToolType.Hand);
                    }
                    break;
                }
                case 17:
                {
                    if (this.ed.tool.ctrl)
                    {
                        this.ed.alt = this.ed.tool.type;
                        this.ed.SetTool(this.ed.tool.ctrl);
                    }
                    break;
                }
                case 16:
                {
                    if (this.ed.tool.shift)
                    {
                        this.ed.alt = this.ed.tool.type;
                        this.ed.SetTool(this.ed.tool.shift);
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (!this.keyed)
            {
                switch(event.keyCode)
                {
                    case 87:
                    {
                        break;
                    }
                    case 83:
                    {
                        break;
                    }
                    case 65:
                    {
                        break;
                    }
                    case 67:
                    {
                        break;
                    }
                    case 68:
                    {
                        break;
                    }
                    case 69:
                    {
                        break;
                    }
                    case 85:
                    {
                        break;
                    }
                    case 76:
                    {
                        break;
                    }
                    case 77:
                    {
                        break;
                    }
                    case 75:
                    {
                        break;
                    }
                    case 73:
                    {
                        break;
                    }
                    case 80:
                    {
                        break;
                    }
                    case 84:
                    {
                        break;
                    }
                    case 86:
                    {
                        break;
                    }
                    case 88:
                    {
                        break;
                    }
                    case 89:
                    {
                        break;
                    }
                    case 90:
                    {
                        break;
                    }
                    case 107:
                    {
                        break;
                    }
                    case 109:
                    {
                        break;
                    }
                    case 78:
                    {
                        break;
                    }
                    case 79:
                    {
                        break;
                    }
                    case 81:
                    {
                        break;
                    }
                    case 74:
                    {
                        break;
                    }
                    case 96:
                    case 48:
                    {
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                switch(event.keyCode)
                {
                    case 8:
                    case 46:
                    {
                        break;
                    }
                    case 88:
                    {
                        break;
                    }
                    case 65:
                    {
                        break;
                    }
                    case 67:
                    {
                        break;
                    }
                    case 86:
                    {
                        break;
                    }
                    case 84:
                    {
                        break;
                    }
                    case 80:
                    {
                        break;
                    }
                    case 89:
                    {
                        break;
                    }
                    case 82:
                    {
                        break;
                    }
                    case 75:
                    {
                        break;
                    }
                    case 77:
                    {
                        break;
                    }
                    case 78:
                    {
                        break;
                    }
                    case 79:
                    {
                        break;
                    }
                    case 87:
                    {
                        break;
                    }
                    case 76:
                    {
                        break;
                    }
                    case 66:
                    {
                        break;
                    }
                    case 69:
                    {
                        break;
                    }
                    case 71:
                    {
                        break;
                    }
                    case 83:
                    {
                        break;
                    }
                    case 85:
                    {
                        break;
                    }
                    case 72:
                    {
                        break;
                    }
                    case 73:
                    {
                        break;
                    }
                    case 90:
                    {
                        break;
                    }
                    case 68:
                    {
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            return;
        }// end function

        public function KeyUp(event:KeyboardEvent) : void
        {
            if (AppState.Modald || AppState.TextInteraction)
            {
                return;
            }
            switch(event.keyCode)
            {
                case 32:
                {
                    this.spaced = false;
                    this.ed.SetTool(this.ed.alt);
                    this.ed.alt = null;
                    break;
                }
                case 17:
                case 16:
                {
                    if (this.ed.alt)
                    {
                        this.ed.SetTool(this.ed.alt);
                        this.ed.alt = null;
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
